Matrix Operations
This lesson discusses various matrix operations.
We'll cover the following
Inverse#
Suppose we have to solve the equation for .
If vector changes, one has to call np.linalg.solve() over and over. Instead, if were calculated once, matrix multiplication with could be done over and over, more efficiently, to obtain different solutions.
The inverse of a matrix may be computed with the inv function of the linalg package.
Let’s use the inverse of the matrix to obtain the solution to the problem in the first lesson.
If the inverse of matrix A is called Ainv, the solution for the equation may be obtained through matrix multiplication of Ainv with the right-hand side. Let’s look at an implementation of this below.
Determinant#
det() from the linalg submodule is used to compute the determinant of the input matrix.
Trace#
trace() from the numpy module is used to compute the trace of the input matrix.
Trace is the sum of the diagonal values of a matrix.
Transpose#
transpose() from the numpy module returns the transpose of the input array.
The transpose of a matrix is a new matrix whose rows are the columns of the original.
Euclidean norm#
The Euclidean norm of an matrix is given by the following equation:
The norm() method from the linalg submodule is used to calculate the Euclidean norm of a matrix.
In the next lesson, we will discuss sparse matrices.
Eigenvalues and Eigenvectors
Sparse Matrices